<template>
	<view class="bank">
		<view class="list" v-if="list.length">
			<view class="bankOne dFlex jStart_aStart" v-for="(item,index) in list" :key='index' @tap.stop='selCard(item)'>
				<view class="bankIcon imgPublic">
					<image src="https://wx.gdxixiashi.com/public/images/person/bank.png" mode="widthFix"></image>
				</view>
				<view class="info dFlex jBetween_aCenter">
					<view class="bankInfo">
						<view class="bankName">{{item.bank}}</view>
						<view class="bankNum">{{item.bank_number}}</view>
					</view>
					<view class="delIcon imgPublic" @tap.stop='delCard(item.id)'>
						<image src="https://wx.gdxixiashi.com/public/images/person/del.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="list empty imgPublic" v-else>
			<image src="../static/images/empty.png" mode="widthFix"></image>
		</view>
		<navigator url="./addBank" hover-class="none" class='btns'>添加银行卡</navigator>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				identity:uni.getStorageSync('identify')?uni.getStorageSync('identify'):'1',
			};
		},
		onShow(){
			this.initBank();
		},
		onShareAppMessage() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		onShareTimeline() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		methods:{
			initBank(){
				this.tool.getData('User/bankList',{
					memberId:uni.getStorageSync('userId'),
				}).then(res=>{
					if(res){
						this.list = res;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 选择银行卡
			selCard(item){
				uni.navigateTo({
					url: './cash?bankId=' + item.id,
				})
				/* let line = this.list[idx];
				let pages = getCurrentPages(); //获取page
				let prevPage = pages[pages.length - 2]; //上一个页面（父页面）
				prevPage.$vm.trueName = line.trueName;
				prevPage.$vm.account = line.bank_number;
				prevPage.$vm.tel = line.tel;
				prevPage.$vm.bank_name = line.bank;
				uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				}); */
			},
			// 删除银行卡
			delCard(id){
				this.tool.getData('User/delbank',{
					id:id
				}).then(res=>{
					if(res){
						this.initBank();
					}
				}).catch(err=>{
					console.log(err);
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: white;
	}
	.bank{
		width: 100%;
		padding: 12px 4%;
		box-sizing: border-box;
		.list{
			width: 100%;
			.bankOne{
				width: 100%;
				padding: 15px;
				box-sizing: border-box;
				margin-bottom: 14.5px;
				color: white;
				background: linear-gradient(#609ff8 0%, #1664ff 100%);
				border-radius: 5px;
				.info{
					flex: 1;
					.delIcon{
						width: 20px;
						height: 20px;
						margin-left: 12px;
					}
					.bankInfo{
						flex: 1;
						.bankName{
							font-size: 13px;
							margin-bottom: 16px;
						}
						.bankNum{
							font-size: 15px;
							font-weight: bold;
						}
					}
				}
				.bankIcon{
					width: 33px;
					height: 33px;
					border-radius: 50%;
					margin-right: 10px;
				}
			}
		}
		.btns{
			width: 100%;
			position: fixed;
			left:0;
			bottom: 0;
			color: white;
			background: linear-gradient(#609ff8 0%, #1664ff 100%);
			border-radius: 5px;
			padding: 12px 0;
			text-align: center;
		}
	}
</style>
